﻿using KqAutoDesign.Models;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;

namespace KqAutoDesign.SonViews
{
    /// <summary>
    /// AddWorkflow.xaml 的交互逻辑
    /// </summary>
    public partial class AddWorkflow : Window, INotifyPropertyChanged
    {
        public AddWorkflow()
        {
            InitializeComponent();
            DataContext = this;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propName));
            }
        }

        private WorkFlowBase _wf;
        public WorkFlowBase SelectedWf
        {
            get {  return _wf; }
            set
            {
                if (_wf != value)
                {
                    _wf = value;
                    RaisePropertyChanged(nameof(SelectedWf));
                }
            }
        }

        public ObservableCollection<WorkFlowBase> Workflows
        {
            get { return App.GlobalConfigs.WorkFlowTemplates; }
        }

        private string _name;
        public string TaskName
        {
            get => _name; set
            {
                if (_name != value)
                {
                    _name = value;
                    RaisePropertyChanged(nameof(TaskName));
                }
            }
        }

        private void OkBtnAction(object sender, RoutedEventArgs e)
        {
            if(string.IsNullOrEmpty(_name))
            {
                MessageBox.Show("任务名称不能为空","提示",MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if(SelectedWf==null)
            {
                MessageBox.Show("工作流不能为空", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            DialogResult = true;
            Close();
        }

        private void CancelBtnAction(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}
